package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.entity.SteelMatter;
import com.sky.entity.SteelMattertype;
import com.sky.mapper.SteelMatterMapper;
import com.sky.mapper.SteelMattertypeMapper;
import com.sky.service.SteelMatterService;
import lombok.val;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
* @author 23714
* @description 针对表【steel_matter】的数据库操作Service实现
* @createDate 2024-09-29 10:45:16
*/
@Service
public class SteelMatterServiceImpl extends ServiceImpl<SteelMatterMapper, SteelMatter>
    implements SteelMatterService{

    // 物料类型
    @Resource
    private SteelMattertypeMapper steelMattertypeMapper;

    // 物料
    @Resource
    private SteelMatterMapper steelMatterMapper;

    @Override
    public List<SteelMatter> getSteelMatterListByTypeId(Integer typeId) {
        List<SteelMatter> list = new ArrayList<>();

        // 判断类型id 下是否有子集
        QueryWrapper<SteelMattertype> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SteelMattertype::getMattertypeParentid,typeId);
        final val count = steelMattertypeMapper.selectCount(queryWrapper);
        if(count>1){
            // 证明有子集
            list= steelMatterMapper.getSteelMatterListByTypeId(typeId);

        }else{
            // 没有子集
            QueryWrapper<SteelMatter> query = new QueryWrapper<>();
            query.lambda().eq(SteelMatter::getMatterTypeId,typeId);
            list=  steelMatterMapper.selectList(query);
        }
        return list;
    }
}




